package com.kaibes.module.email.sender;

import java.util.List;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.kaibes.web.api.ApiLink;
import com.kaibes.web.api.ResponseApi;
import com.kaibes.web.response.ResponseFactory;

@RestController
@RequestMapping("/emails/templates")
public class MailTemplateApi extends ResponseApi<MailTemplate, MailTemplateService> {

    @PostMapping
    @ApiLink("创建邮件模板")
    public ResponseEntity<List<Number>> post(@RequestBody MailTemplatePost data) {
        return super.post(data, "创建邮件模板成功", "创建邮件模板失败");
    }
    
    @PutMapping("/{key}")
    @ApiLink("更新邮件模板")
    public ResponseEntity<Object> put(@PathVariable String key, @RequestBody MailTemplatePut data) {
        return ResponseFactory.put(service.updateByKey(data, key), "更新邮件模板成功", "更新邮件模板失败");
    }
    
    @DeleteMapping("/{key}")
    @ApiLink("删除邮件模板")
    public ResponseEntity<Object> delete(@PathVariable String key) {
        return ResponseFactory.delete(service.removeByKey(key), "删除邮件模板成功", "删除邮件模板失败");
    }
    
}
